sch_files=polycam_1.sch polycam_2.sch polycam_3.sch polycam_4.sch polycam_5.sch

pcb: polycam.pcb
polycam.pcb: polycam.drc
	gsch2pcb helper/project

drc: polycam.drc
polycam.drc: $(sch_files) helper/drc_rules.txt
	gnetlist  -g drc2 -l helper/drc_rules.txt \
		-O ignore-warnings-in-return-value -o polycam.drc $(sch_files)
	@echo
	@grep -v ERROR polycam.drc &>/dev/null
	@echo "DRC Passed"

pdf: pdf-bw

pdf-color: polycam-color.pdf
polycam-color.pdf: $(sch_files) helper/gafrc.print helper/print-color.scm
	gschem -p -shelper/print-color.scm -rhelper/gafrc.print \
		-opolycam_1.ps polycam_1.sch
	gschem -p -shelper/print-color.scm -rhelper/gafrc.print \
		-opolycam_2.ps polycam_2.sch
	gschem -p -shelper/print-color.scm -rhelper/gafrc.print \
		-opolycam_3.ps polycam_3.sch
	gschem -p -shelper/print-color.scm -rhelper/gafrc.print \
		-opolycam_4.ps polycam_4.sch
	gschem -p -shelper/print-color.scm -rhelper/gafrc.print \
		-opolycam_5.ps polycam_5.sch
	gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite \
		-sOutputFile=polycam-color.pdf *.ps
	rm *.ps

pdf-bw: polycam.pdf
polycam.pdf: $(sch_files) helper/gafrc.print helper/print-bw.scm
	gschem -p -shelper/print-bw.scm -rhelper/gafrc.print \
		-opolycam_1.ps polycam_1.sch
	gschem -p -shelper/print-bw.scm -rhelper/gafrc.print \
		-opolycam_2.ps polycam_2.sch
	gschem -p -shelper/print-bw.scm -rhelper/gafrc.print \
		-opolycam_3.ps polycam_3.sch
	gschem -p -shelper/print-bw.scm -rhelper/gafrc.print \
		-opolycam_4.ps polycam_4.sch
	gschem -p -shelper/print-bw.scm -rhelper/gafrc.print \
		-opolycam_5.ps polycam_5.sch
	gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite \
		-sOutputFile=polycam.pdf *.ps
	rm *.ps

refdes:
#	refdes_renum --pgskip $(sch_files)
	@echo "Use the 'Attributes -> Autonumber Text...' function in gschem."
	@false

dist: clean pdf-color pdf-bw
	tar --exclude attic --exclude reference --exclude .svn \
	   -jcvf ../polycam-hardware.tar.bz2 ../polycam-hardware/

clean:
	rm -f *.log *~ *.save *.ps *.pdf *.drc board.pcb-
